package rtda

import "lesson01/rtda/heap"

const stackSize = 1024

type Thread struct {
	pc    int
	stack *Stack
}

func NewThread() *Thread {
	return &Thread{
		stack: newStack(stackSize),
	}
}

func (e *Thread) PC() int {
	return e.pc
}

func (e *Thread) SetPC(pc int) {
	e.pc = pc
}

func (e *Thread) PushFrame(frame *Frame) {
	e.stack.push(frame)
}

func (e *Thread) PopFrame() *Frame {
	return e.stack.pop()
}

func (e *Thread) CurrentFrame() *Frame {
	return e.stack.top()
}

func (e *Thread) TopFrame() *Frame {
	return e.stack.top()
}

func (e *Thread) IsStackEmpty() bool {
	return e.stack.isEmpty()
}

func (e *Thread) NewFrame(method *heap.Method) *Frame {
	return newFrame(e, method)
}
